package UIUtils {
	import flash.events.TimerEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
	
	public class uif_utilA extends Object {
		
		public static function cloneArr(arr: Array): Array {
			var result: Array = new Array();
			for (var i: int =0; i<arr.length; i++)
				result[i] = clone(arr[i]);
			return result;
		}
		
		public static function snb(obj: Object): Boolean {
			return (obj is String) || (obj is Number) || (obj is Boolean);
		}
		
		public static function createAs(obj: Object): Object {
			return (obj is Array)?(new Array()):(
						(obj.hasOwnProperty('clone'))?obj.clone():
							(
								(obj is Object)?((obj is Function)?obj:(
									(obj is Class)?obj:(new Object())
								)):null
							)
					)
		}  
		
		public static function clone(obj: Object): Object {
			if (snb(obj)) return obj;
			if (obj is Array) return cloneArr(obj as Array);
			if (obj.hasOwnProperty('clone')) return obj.clone();
			
			var result: Object = new Object();
			for (var i: String in obj)
				if (obj[i] is Array)
					result[i] = cloneArr(obj[i]);
				else if (obj[i] is Object)
					result[i] = clone(obj[i]);
				else result[i] = obj[i];
			return result;			
		}
		
		public static function unionObj(obj1: Object, obj2: Object): Object {
			return union(clone(obj1), clone(obj2));
		}
		
		public static function union(obj1: Object, obj2: Object): Object {
			var newObj: Object = createAs(obj1?obj1:obj2);
			var i: String;
			for (i in obj1) newObj[i] = obj1[i];
			for (i in obj2) {
				if (snb(obj2[i])) newObj[i] = obj2[i]; 
				else newObj[i] = union(newObj[i], obj2[i]);
			}
			return newObj;
		}
	}
}